package CtrLayer;
import ModelLayer.*;

/**
 * PersonCtr collect and control methods related to class Person and class PersonContainer. 
 * 
 * @author Gruppe 3
 * @version 20-12-2011
 */



public class PersonCtr
{
    private PersonContainer personContainer;
    private Person customer;
    private Person employee;
    private static PersonCtr instance;

    /**
     * Constructs an object of class PersonCtr and intialize personContainer. 
     */
    
    public PersonCtr()
    {
        personContainer = personContainer.getInstance();
        Person admin = new Employee("admin", "11111111", "ingen", "ingen", "ingen", "admin", "1234", 0, "admin");
        personContainer.addEmployee(admin);
        
    }
    
    public static PersonCtr getInstance()
    {
        if(instance==null)
        {
            instance = new PersonCtr();
        }
        return instance;
    }
    
    /**
     * Finds a customer by returning an object of the type Person by searching on either phoneNumber or customerId.
     * 
     * @param phoneNumber, the phone number of the customer wished searched for.  
     * @param customerId, the customer ID of the customer wished searched for. 
     * @return customer, the customer with a matching phone number or customer ID.
     */
    
    public Person findCustomer(String phoneNumber, int customerId)
    {
        customer = personContainer.findCustomer(phoneNumber, customerId);
        return customer;
    }
    
    /**
     * Finds an employee by checking userName and password and returns the matching employee.
     * 
     * @param userName, the employee's username. 
     * @param password, the employee's password. 
     * @return employee, the employee with a matching username and password.
     */
    
    public Person logOn(String userName, String password)
    {
      employee = personContainer.logOn(userName, password);
      return employee;
    }
    
    /**
     * Creates a new employee and adds him/her to the personContainer. 
     * 
     * @param name, the name of the employee.
     * @param phoneNumber, the phone number of the employee.
     * @param address, the address of the employee. 
     * @param city, the city of the employee. 
     * @param zipCode, the zip code of the employee.
     * @param userName, the username of the employee. 
     * @param password, the password of the employee. 
     * @param wage, the employee's monthly wage.
     * @param employeeRole, the employee's employee role.
     */
    
    public void createEmployee(String name, String phoneNumber, String address, String city, String zipCode, String userName, String password, double wage, String employeeRole)
    {
        Person employee2 = new Employee(name, phoneNumber, address, city, zipCode, userName, password, wage, employeeRole);
        personContainer.addEmployee(employee2);
    }
    
    /**
     * Creates a new private customer and adds him/her to the personContainer.
     * 
     * @param name, the name of the customer.
     * @param phoneNumber, the phone number of the customer.
     * @param address, the address of the customer. 
     * @param city, the city of the customer. 
     * @param zipCode, the zip code of the customer.
     * @param customerGroup, the customerGroup the customer belongs to. 
     */
    
    public void createCustomer(String name, String phoneNumber, String address, String city, String zipCode, int customerGroup)
    {
       Person customer = new Customer(name, phoneNumber, address, city, zipCode, customerGroup);
       personContainer.addCustomer(customer);
    }
    
     /**
     * Creates a new business customer and adds him/her to the personContainer.
     * 
     * @param name, the name of the customer. 
     * @param phoneNumber, the phone number of the customer.
     * @param address, the address of the customer. 
     * @param city, the city of the customer. 
     * @param zipCode, the zip code of the customer.
     * @param customerGroup, the customerGroup the customer belongs to. 
     * @param cvrNumber, the CVR number of the customer. 
     */
    
    public void createBusiness(String name, String phoneNumber, String address, String city, String zipCode, int customerGroup, String cvrNumber)
    {
       Person businessCustomer = new BusinessCustomer(name, phoneNumber, address, city, zipCode, customerGroup, cvrNumber);
       personContainer.addCustomer(businessCustomer);
    }
    
    public Person getCustomer()
    {
    	return customer;
    }
    
    public Person getLogOn()
    {
    	return employee;
    }
    
}
